﻿using Org.BouncyCastle.Asn1.X509;
using StudySystem.SQLServer;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StudySystem.MainLogic.Items
{
    public enum AnswerResult
    {
        WRONG = 0,
        VAGUE = 1,
        RIGHT = 2
    }
    public class ClassRecord
    {
        private string _subjectID;
        private string _questionID;
        private AnswerResult _answerResult;
        private DateTime _answerTime;

        public string SubjectID { get => _subjectID; set => _subjectID = value; }
        public string QuestionID { get => _questionID; set => _questionID = value; }
        public DateTime AnswerTime { get => _answerTime; set => _answerTime = value; }
        public AnswerResult AnswerResult { get => _answerResult; set => _answerResult = value; }
    
        public ClassRecord(string subjectID, string questionID, AnswerResult result)
        {
            this.SubjectID = subjectID;
            this.QuestionID = questionID;
            this.AnswerTime = DateTime.Now;
            this.AnswerResult = result;
        }
        public ClassRecord(DataRow dr)
        {
            SubjectID = dr["SubjectID"].ToString();
            QuestionID = dr["QuestionID"].ToString();
            AnswerTime = DateTime.Parse(dr["Date"].ToString());
            AnswerResult = (AnswerResult)int.Parse(dr["Result"].ToString());
        }

        public static void InsertARecord(ClassQuestion question,AnswerResult result)
        {
            //数据库更新
            DBForRecord.InsertARecord(question.SubjectID, question.QuestionID, result);
            //内存更新
            question.Records.Add(new ClassRecord(question.SubjectID, question.QuestionID, result));
            
        }

        

    }
}
